//
//  UpdateInfoView.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/9.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "UpdateInfoView.h"
@interface UpdateInfoView()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *doneBtnLeft; // 94 // 25
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UILabel *info;
@property (weak, nonatomic) IBOutlet UIButton *doneBtn;
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;

@end
@implementation UpdateInfoView

INITFROMXIB

- (void)awakeFromNib{
    [super awakeFromNib];
    self.bgView.layer.cornerRadius = 10.0;
    self.bgView.layer.masksToBounds = YES;
}

- (void)showInView:(UIView *)view{
    [view addSubview:self];
    [self show];
}

- (void)show{
    self.backgroundColor = [UIColor clearColor];
    self.bgView.transform = CGAffineTransformScale(CGAffineTransformIdentity,CGFLOAT_MIN,CGFLOAT_MIN);
   
    
    [UIView animateWithDuration:0.15
                     animations:^{
        self.bgView.transform = CGAffineTransformIdentity;
        self.backgroundColor = [[UIColor alloc] initWithWhite:0 alpha:0.8];
    }
                     completion:^(BOOL finished) {
     
    }];
    
    
    
    
}

- (void)hide{
    
    [UIView animateWithDuration:0.15
                     animations:^{
        self.backgroundColor = [UIColor clearColor];
        self.bgView.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.1,0.1);
    }
                     completion:^(BOOL finished) {
        [self removeFromSuperview];
     
    }];
}
- (IBAction)doneAction:(id)sender {
    if (self.actionBlock) {
        self.actionBlock(1);
        [self hide];
    }
}

- (IBAction)cancelAction:(id)sender {
    if (self.actionBlock) {
        self.actionBlock(0);
        [self hide];
    }
}


- (void)refreshWithModel:(VersionModel *)verM{
    BOOL isNeedUpdate = verM.isNeedUpdate;
    BOOL isForce = isNeedUpdate && verM.force;
    self.cancelBtn.hidden = !isNeedUpdate;
    self.title.text = isNeedUpdate ? LCLocalString(@"update_bbgx") : LCLocalString(@"no_update");
    self.info.text = verM.versionDescribe;
    [self.doneBtn setTitle:isNeedUpdate? LCLocalString(@"update_ljgx") : LCLocalString(@"zdl") forState:(UIControlStateNormal)];
    
    
    self.doneBtnLeft.constant = (!isNeedUpdate || isForce) ? 25 : 94;
 
}



@end
